export

ifeq ($(OPENSSLDIR),)
#$(error "OpenSSL Directory NOT SPECIFIED")
endif

PROGEXT:=
ifeq ($(shell uname -o),Cygwin)
PROGEXT:=.exe
else
DEPLIBS+=dl
endif

debug: CFLAGS+=-g

ifeq ($(BUILDDIR),)
BUILDDIR:=../build
else
EXTRAOBJS+=$(wildcard $(BUILDDIR)/*.o)
endif

VPATH:=$(VPATH):$(BUILDDIR)

PROGNAME:=signver
#PARTS:=load_engine main apps
PARTS:=load_engine main
LIBNAMES:=
DEPLIBS+=crypto
LINKLIBS:=$(foreach lib,$(LIBNAMES) $(DEPLIBS),-l$(lib))

PROG:=$(PROGNAME)$(PROGEXT)
SRCS:=$(foreach part,$(PARTS),$(part).c)
OBJS+=$(foreach part,$(PARTS),$(BUILDDIR)/$(part).o)
LIBS:=$(foreach lib,$(LIBNAMES),lib$(lib).a)

all: debug

release debug: $(PROG)

$(PROG): $(OBJS) $(LIBS)
	$(CC) $(LFLAGS) -L$(OPENSSLDIR) -L$(EXTRADIR) -o $(BUILDDIR)/$@ $(OBJS) $(EXTRAOBJS) $(LINKLIBS)

$(BUILDDIR)/%.o: %.c
	$(CC) $(CFLAGS) -I$(OPENSSLDIR)/include -I$(OPENSSLDIR)  -o $@ -c $^

clean:
	rm -f $(OBJS) $(BUILDDIR)/$(PROG)


